package com.huawei.hwCloudJs;

import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;
import com.huawei.hwCloudJs.api.ILocDialog;
import com.huawei.hwCloudJs.api.ValidateWhiteListListener;
import com.huawei.hwCloudJs.api.WebviewDownloadListenner;
import com.huawei.hwCloudJs.api.WebviewFileChooserListenner;
import com.huawei.hwCloudJs.core.JSRequest;
import com.huawei.hwCloudJs.core.d;
import com.huawei.hwCloudJs.service.debugtool.SetUrl;
import com.huawei.hwCloudJs.service.debugtool.SetUrl.GetUrlCallBack;
import com.huawei.hwCloudJs.service.hms.a.b;
import com.huawei.hwCloudJs.service.jsapi.JsCoreApi;
import com.huawei.hwCloudJs.service.jsmsg.NativeMsg;
import com.huawei.hwCloudJs.service.locationapi.DefaultPermissionDlg;
import com.huawei.hwCloudJs.service.locationapi.GetLocationApi;
import com.huawei.hwCloudJs.service.locationapi.a.a;
import com.huawei.hwCloudJs.support.a.c;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsClientApi {
    private static final Map<String, HWCloudJSBridge> a = new HashMap();
    private static Class b;
    private static Class c;
    private static HashMap<String, Class> d;
    private static WebviewFileChooserListenner e;
    private static WebviewDownloadListenner f;
    private static String g;
    private static boolean h;
    private static int i;

    public static final class SdkOpt {
        private boolean a = true;

        public static final class Builder {
            private boolean a = true;

            public SdkOpt build() {
                SdkOpt sdkOpt = new SdkOpt();
                sdkOpt.a = this.a;
                return sdkOpt;
            }

            public Builder setShowAuthDlg(boolean z) {
                this.a = z;
                return this;
            }
        }
    }

    static {
        registerJsApi(JsCoreApi.class);
        registerJsApi(GetLocationApi.class);
        registerExtKit(DefaultPermissionDlg.class);
    }

    public static void clearUserPermissionSet() {
        a.a().b();
    }

    public static String createApi(WebView webView) {
        com.huawei.hwCloudJs.b.a.a(webView.getContext());
        HWCloudJSBridge hWCloudJSBridge = new HWCloudJSBridge();
        hWCloudJSBridge.attach(webView);
        String bridgeId = hWCloudJSBridge.getBridgeId();
        synchronized (a) {
            a.put(bridgeId, hWCloudJSBridge);
        }
        return bridgeId;
    }

    public static String createApi(WebView webView, SdkOpt sdkOpt) {
        if (sdkOpt != null) {
            com.huawei.hwCloudJs.b.a.a(sdkOpt.a);
        }
        return createApi(webView);
    }

    public static void destroyApi(String str) {
        synchronized (a) {
            HWCloudJSBridge hWCloudJSBridge = (HWCloudJSBridge) a.remove(str);
            if (hWCloudJSBridge != null) {
                hWCloudJSBridge.detach();
            }
        }
        d.a().a(str);
    }

    public static void finishAllwebview() {
        if (com.huawei.hwCloudJs.b.a.c() != null) {
            com.huawei.hwCloudJs.b.a.c().ˋ(new Intent("com.huawei.jssdk.finishAll"));
        }
    }

    public static Class getjsActionbarClass() {
        return b;
    }

    public static HashMap<String, Class> getjsInterfacemap() {
        return d;
    }

    public static Class getjsWebviewClass() {
        return c;
    }

    public static void handleActivityPermissionResult(int i, String[] strArr, int[] iArr) {
        com.huawei.hwCloudJs.support.b.d aVar = new com.huawei.hwCloudJs.service.locationapi.a.a();
        aVar.a(i);
        aVar.a(iArr);
        com.huawei.hwCloudJs.service.locationapi.a.a().a(aVar);
    }

    public static void handleActivityResult(int i, int i2, Intent intent) {
        com.huawei.hwCloudJs.support.b.d bVar = new b();
        bVar.a(intent);
        bVar.b(i);
        bVar.a(i2);
        com.huawei.hwCloudJs.service.hms.a.a().a(bVar);
    }

    public static boolean isUrlWhileList(String str) {
        return com.huawei.hwCloudJs.service.a.b.a().b(str);
    }

    public static boolean isneedoriginalUserAgent() {
        return h;
    }

    public static void notifyNativeMsg(NativeMsg nativeMsg) {
        if (nativeMsg != null) {
            com.huawei.hwCloudJs.service.jsmsg.a.a().a((com.huawei.hwCloudJs.support.b.d) nativeMsg);
        }
    }

    public static void notifyNativeMsgToBridge(String str, NativeMsg nativeMsg) {
        if (nativeMsg != null) {
            synchronized (a) {
                HWCloudJSBridge hWCloudJSBridge = (HWCloudJSBridge) a.get(str);
                if (hWCloudJSBridge != null) {
                    hWCloudJSBridge.onReceive(nativeMsg);
                }
            }
        }
    }

    public static void preload(String[] strArr, int i, Context context) {
        c.a(strArr, i, context);
    }

    public static void registerActionbarClass(Class cls) {
        b = cls;
    }

    public static void registerExtKit(Class<? extends ILocDialog> cls) {
        com.huawei.hwCloudJs.core.extKit.a.a(com.huawei.hwCloudJs.core.extKit.b.a, cls);
    }

    public static void registerJsApi(Class<? extends JSRequest> cls) {
        com.huawei.hwCloudJs.core.a.b.a().a((Class) cls);
        if (com.huawei.hwCloudJs.core.c.class.isAssignableFrom(cls)) {
            d.a().a((Class) cls);
        }
    }

    public static void registerUrlWhiteList(List<String> list) {
        if (list != null) {
            for (String a : list) {
                com.huawei.hwCloudJs.service.a.b.a().a(a);
            }
        }
    }

    public static void registerValidateWhiteListListener(ValidateWhiteListListener validateWhiteListListener) {
        com.huawei.hwCloudJs.service.a.b.a();
        com.huawei.hwCloudJs.service.a.b.a(validateWhiteListListener);
    }

    public static void registerWebSettingsMixmode(int i) {
        i = i;
    }

    public static void registerWebviewClass(Class cls) {
        c = cls;
    }

    public static void registerWebviewFileChooserListenner(WebviewFileChooserListenner webviewFileChooserListenner) {
        e = webviewFileChooserListenner;
    }

    public static void registerjsInterface(HashMap<String, Class> hashMap) {
        d = hashMap;
    }

    public static void registerwebViewDownLoadListener(WebviewDownloadListenner webviewDownloadListenner) {
        f = webviewDownloadListenner;
    }

    public static void registerwebViewUserAgentString(String str, boolean z) {
        g = str;
        h = z;
    }

    public static void setJSOption(SdkOpt sdkOpt) {
        if (sdkOpt != null) {
            com.huawei.hwCloudJs.b.a.a(sdkOpt.a);
        }
    }

    public static void setJsUrl(String str) {
        a.a().b(str);
    }

    public static void setMaxCacheSize(long j) {
        com.huawei.hwCloudJs.support.a.b.a().a(j);
    }

    public static void setUrlToWebView(GetUrlCallBack getUrlCallBack) {
        SetUrl.a().a(getUrlCallBack);
    }

    public static void unRegisterJsApi(String str) {
        com.huawei.hwCloudJs.core.a.b.a().a(str);
    }

    public static int webSettingsMixmode() {
        return i;
    }

    public static WebviewDownloadListenner webViewDownLoadListener() {
        return f;
    }

    public static String webViewUserAgentString() {
        return g;
    }

    public static WebviewFileChooserListenner webviewFileChooserListenner() {
        return e;
    }
}
